﻿using EFCore.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SService;

namespace WMSWeb.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class SysRoleController : ControllerBase
    {
        private readonly WmssystemContext myDbContext;
        private readonly SysRoleS SysRoleS;

        public SysRoleController(WmssystemContext myDbContext, SysRoleS SysRoleS)
        {
            this.myDbContext = myDbContext;
            this.SysRoleS = SysRoleS;
        }
        /// <summary>
        /// 角色管理分页模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("FenYe")]
        public async Task<List<SysRole>> FenYe(int pageSize, int currentPage, string Name = null, bool? Status = null)
        {
            return await SysRoleS.FenYe(pageSize, currentPage, Name, Status);
        }
        /// <summary>
        /// 角色管理添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<int>> Add(SysRole roleAdd)
        {
            // 为实体的属性赋值
            roleAdd.RRnumber = 0;
            roleAdd.RRisDelete = true;
            roleAdd.RRcreateTime = DateTime.Now;
            roleAdd.RRcreateUser = 1;
            roleAdd.RRupdateTime = null;
            roleAdd.RRupdateUser = null;

            // 调用服务层的方法执行添加操作
            return await SysRoleS.Add(roleAdd);
        }
        /// <summary>
        /// 角色管理修改
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public async Task<ActionResult<int>> Update(SysRole roleUpd)
        {
            // 为实体的属性赋值
            roleUpd.RRupdateTime = DateTime.Now;
            roleUpd.RRupdateUser = 1;

            return await SysRoleS.Upd(roleUpd);
        }
        /// <summary>
        /// 角色管理逻辑删除
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdIsDelete")]
        public async Task<ActionResult<int>> UpdIsDelete(int id, bool isDeleted)
        {
            return await SysRoleS.UpdIsDelete(id, isDeleted);
        }
    }
}
